/*
 * myMacros.h
 *
 *  Created on: 2013. 3. 16.
 *      Author: jaty
 */

#ifndef __MYMACROS_H__
#define __MYMACROS_H__

#define ERROR_RESULT                    -1

#define EXCEPTION_CHECK( func_call, error_msg, exit_func_call )\
do {\
   try {\
       if( func_call  < 0) {\
           myException *error_ret = new myException(errno, error_msg);\
           throw error_ret;\
       }\
   }\
   catch (myException *err_ret) {\
       err_ret->outputError();\
       delete err_ret;\
       exit_func_call;\
   }\
} while(0)

#define TRAVERSE(limit_num) for(int i=0; i<limit_num; i++)


// Signal Related

#define INIT_COND_MUTEX(cond, mutex)\
do {\
    pthread_mutex_init(&mutex, 0);\
    pthread_cond_init(&cond, 0);\
} while(0)

#define DESTROY_COND_MUTEX(cond, mutex)\
do {\
        pthread_mutex_destroy(&mutex);\
        pthread_cond_destroy(&cond);\
} while(0)

#define COND_WAIT(cond, mutex) \
do {\
    pthread_mutex_lock(&mutex);\
    pthread_cond_wait(&cond, &mutex);\
    pthread_mutex_unlock(&mutex);\
} while(0)

#define SEND_COND_SIG(cond, mutex)\
do {\
    pthread_mutex_lock(&mutex);\
    pthread_cond_signal(&cond);\
    pthread_mutex_unlock(&mutex);\
} while(0)

#define MUTEX_INIT(mutex)               pthread_mutex_init(&mutex, 0);
#define MUTEX_DESTROY(mutex)    pthread_mutex_destroy(&mutex);
#define MUTEX_LOCK(mutex)               pthread_mutex_lock(&mutex);
#define MUTEX_UNLOCK(mutex)             pthread_mutex_unlock(&mutex);

// STL Related
#define FORLOOP_CONTAINER(cont, it)     for(it=cont.begin(); it!=cont.end(); it++)


#define LOOPBACK_IP                     "127.0.0.1"


#endif
